/**
 路由分组
 运行多个服务
 */
package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"time"

	"golang.org/x/sync/errgroup"
)

var (
	g errgroup.Group
)

func main() {
	s1 := &http.Server{
		Addr: ":8080",
		Handler: router01(),
		ReadTimeout: 5 * time.Second,
		WriteTimeout: 5 * time.Second,
	}

	s2 := &http.Server{
		Addr: ":8081",
		Handler: router02(),
		ReadTimeout: 5 * time.Second,
		WriteTimeout: 5 * time.Second,
	}
}

func router01() http.Handler {
	r := gin.Default()
	// 路由分组，v1 版本
	v1 := r.Group("/v1")
	{
		v1.POST("/login", loginEndpoint)
		v1.GET("/user", userEndpoint)
	}
	return r
}

func router02() http.Handler {
	r := gin.Default()
	v2 := r.Group("/v2")
	{
		v2.POST("/login", loginEndpoint)
		v2.GET("/user", userEndpoint)
	}
	return r
}

func userEndpoint(context *gin.Context) {

}

func loginEndpoint(context *gin.Context) {

}
